package cn.tedu.oa.room.service.impl;

import cn.tedu.oa.room.mapper.RoomMapper;
import cn.tedu.oa.room.pojo.dto.RoomQuery;
import cn.tedu.oa.room.pojo.dto.RoomSaveParam;
import cn.tedu.oa.room.pojo.entity.Room;
import cn.tedu.oa.room.pojo.vo.RoomVO;
import cn.tedu.oa.room.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;


    @Override
    public List<RoomVO> select(RoomQuery roomQuery) {
        log.info("RoomServiceImpl.select()");
        List<RoomVO> list = roomMapper.select(roomQuery);
        return list;
    }

    @Override
    public void save(RoomSaveParam roomSaveParam) {
        log.info("RoomServiceImpl.save()");
        Room room = new Room();
        BeanUtils.copyProperties(roomSaveParam,room);
        if (room.getId()==null){
            log.info("新增"+room);
            room.setCreatedDate(new Date());
            roomMapper.insert(room);
        }else {
            log.info("修改"+room);
            room.setUpdatedDate(new Date());
            roomMapper.update(room);
        }

    }

    @Override
    public void delete(Integer id) {
        log.debug("删除业务，参数：{}",id);
        roomMapper.delete(id);
    }
}
